import request from '../utils/axios'

//http://8.152.193.207:3000/api/
//接口网址

// 创建新表
export function createMeter(alias, type, range, unit) {
  return request({
    url: `/api/create${type}`, // 使用模板字符串正确拼接URL
    headers:{
      "authorization": "aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data: { alias, range, unit } // 确保发送 alias, range, unit 这三个数据
  });
}

// 创建三叉表
export function createTrifurcateMeter(alias, type, range, unit) {
  return request({
    url: `/api/create${type}`, // 使用模板字符串正确拼接URL
    headers:{
      "authorization": "aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data: { alias, range, unit } // 确保发送 alias, range, unit 这三个数据
  });
}

// 创建指示器
export function createIndicatorMeter(alias, type, range, unit) {
  return request({
    url: `/api/create${type}`, // 使用模板字符串正确拼接URL
    headers:{
      "authorization": "aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data: { alias } // 确保发送 alias 这个数据
  });
}

// 创建监控
export function createMonitor(meterId, monitorId,type) {
  return request({
    url: '/api/createMonitor',
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data:{meterId, monitorId,type}
  })
}


// 获取某种类型的表数据
export function getAllMeters(type) {
  return request({
    url: `/api/getTypeMeter/`,
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'get',
    params: {
      type
    }
  })
}

// 获取特定表数据
// 获取单个表的详细的信息
export function queryMeter(type, alias, monitorId) {
  return request({
    url: '/api/query_meter',
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'get',
    params: {
      type,
      alias,
      monitorId
    }
  })
}


// 获取表详情
//获取单个表的监控详情
export function getMeterDetails(meterId, type) {
  return request({
    url: `/api/getMeterInfo`,
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data: {
      meterId,
      type,
    }
  })
}

// 刷新详细信息
export function refreshDetails(monitorId) {
  return request({
    url: '/api/getNewestMonitor',
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'GET',
    params: {
      monitorId
    }
  })
}



// 更新表别名
export function updateMeterAlias(meter_id, alias) {
  return request({
    url: `/api//updataMeterAlias`,
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'put',
    params: {meter_id},
    data: { alias }
  })
}

// 搜索框 搜索
export function quaryMeter(meterId, alias, type, monitorId) {
  return request({
    url: `/api/quaryMeter`,
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'post',
    data: {
      meterId,
      alias,
      type,
      monitorId
    }
  });
}



///获取刷新的次数
export function getIncrement(){
  return request({
    url: `/api/getIncrement`,
    headers:{
      "authorization":"aaec1f392fb6831833f7f3b70249361e"
    },
    method: 'get',
  })
}